﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BanHangCshap.Class
{
    class ChungLoaiHang:Database
    {
       
        #region ***** Fields & Properties ***** 
		private string _machungloai;
		public string machungloai
		{ 
			get 
			{ 
				return _machungloai;
			}
			set 
			{ 
				_machungloai = value;
			}
		}
		private string _tenchungloai;
		public string tenchungloai
		{ 
			get 
			{ 
				return _tenchungloai;
			}
			set 
			{ 
				_tenchungloai = value;
			}
		}
		#endregion

		#region ***** Init Methods ***** 
		public ChungLoaiHang()
		{
           
		}
		public ChungLoaiHang(string machungloai)
		{
            string sql = "select * from ChungLoaiHang where machungloai = '" + machungloai + "'";
            foreach (DataRow dr in getDataTable(sql).Rows)
            {
                this.machungloai = machungloai;
                this.tenchungloai = dr["tenchungloai"].ToString().Trim();
            }
		}
		public ChungLoaiHang(string machungloai, string tenchungloai)
		{
			this.machungloai = machungloai;
			this.tenchungloai = tenchungloai;
		}
		#endregion
        public Boolean isExistChungLoaiHang(string machungloai)
        {
            string sql = "select * from ChungLoaiHang where machungloai = '" + machungloai + "'";
            return isExist(sql);
        }
        public string taoMaChungLoai()
        {
            string sql = "select max(convert(int,machungloai)) from ChungLoaiHang";
            return string.Format("{0,2:00}", getNumberValue(sql) + 1);
        }

        public DataTable layDSChungLoaiHang()
        {

            string sql = "select machungloai, tenchungloai from ChungLoaiHang";
            return getDataTable(sql);
        }
        public Boolean themChungLoaiHang()
        {
            string sql = "insert into ChungLoaiHang(machungloai,tenchungloai) values ('" + machungloai + "',N'" + tenchungloai + "')";
            return executeQuery(sql);
        }
        public Boolean xoaChungLoaiHang(string machungloai)
        {
            string sql = "delete ChungLoaiHang where machungloai = '" + machungloai + "'";
            return executeQuery(sql);
        }
        public Boolean suaChungLoaiHang()
        {
            string sql = "update ChungLoaiHang set tenchungloai= N'" + tenchungloai + "' where machungloai = '" + machungloai + "'";
            return executeQuery(sql);
        }
        
        public DataTable layDSLoaiHang(string machungloai)
        {
            string sql = "select maloai,tenloai from LoaiHang where machungloai = '" + machungloai + "'";
            return getDataTable(sql);
        }
    }
}
